<?php
/*
 * Created on Feb 10, 2009
 * @ ANH:
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
class place_Model_City extends Clu_Db_Table_Abstract
{
    //only specify the table name, everything else inherits
	protected $_name = "cities";
	protected $_primary = "city_id";
	
	public function findByPrimary($id)
	{
		if (!$id)
            return null;
        else
		    return $this->fetchRow('city_id = ' . $this->getAdapter()->quote($id, 'INTEGER'));
	}
	
	public function findForSelect()
    {
    	$select = $this->getAdapter()->select()
    								 ->from(array('c' => 'cities'));
    								
    	$select->order(array('weight', 'status'));
    	$ret = $this->getAdapter()->fetchAll($select);
    	
    	foreach($ret as $key=>$city)
		{
			$ret[$key]['metadata'] = unserialize($city['metadata']);
		}
		return $ret;
    }
    
    public function getCityName($id)
	{
		$db = $this->getAdapter();
	    $sql = "SELECT c.city_name FROM cities c WHERE city_id =" .$db->quote($id,'INTEGER');
		return $db->fetchRow($sql);
	}
	
	public function updateNumberOfPlacesByCity()
	{

	}
	/*
	public function getCityName($ids)
	{
		$db = new Zend_Db_Adapter_Pdo_Mysql(array(
		    'host'     => '127.0.0.1',
		    'username' => 'root',
		    'password' => '123',
		    'dbname'   => 'anh'
		));
		$sql = 'SELECT cityname FROM test WHERE id IN ='.$ids;
		$result = $db->fetchRow($sql);
		return $result['cityname'];
	}
	*/
}
?>
